﻿namespace My.Hydrator.Tests.Formatters
{
    using System;
    using System.ComponentModel.DataAnnotations;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using My.Hydrator.Formatters;

    [TestClass]
    public class DateTimeDataTypeFormatterTests
    {
        private readonly DateTime minDate = new DateTime(2000, 1, 1);

        private readonly DateTime maxDate = DateTime.Now;

        private Hydrator hydrator;

        [TestInitialize]
        public void SetUp()
        {
            this.hydrator = new Hydrator();

            this.hydrator.Configure(x => x.For(DataType.DateTime).Use(new DateTimeDataTypeFormatter(this.minDate, this.maxDate)));
        }

        [TestMethod]
        public void HydrationShouldPassForValidTypes()
        {
            for (var i = 0; i < 25000; i++)
            {
                var result = this.hydrator.Hydrate<FormatterTestClass>();

                Assert.IsTrue(result.DateTime1 >= this.minDate && result.DateTime1 <= this.maxDate, string.Format("DateTime1: {0} >= {1} && {0} <= {2}", result.DateTime1, this.minDate, this.maxDate));
                Assert.IsTrue(result.DateTime2 >= this.minDate && result.DateTime2 <= this.maxDate, string.Format("DateTime2: {0} >= {1} && {0} <= {2}", result.DateTime2, this.minDate, this.maxDate));
            }
        }
    }
}
